package com.autoai.util;

public class StringUtiltil {
    /**
     * 截取字符串str中指定字符 strStart、strEnd之间的字符串
     *

     */
    public static String subString(String str, String strStart, String strEnd) {

        /* 找出指定的2个字符在 该字符串里面的 位置 */
        int strStartIndex = str.indexOf(strStart);
        int strEndIndex = str.indexOf(strEnd);

        /* index 为负数 即表示该字符串中 没有该字符 */
        if (strStartIndex < 0) {
            return "字符串 :---->" + str + "<---- 中不存在 " + strStart + ", 无法截取目标字符串";
        }
        if (strEndIndex < 0) {
            return "字符串 :---->" + str + "<---- 中不存在 " + strEnd + ", 无法截取目标字符串";
        }
        /* 开始截取 */
        String result = str.substring(strStartIndex, strEndIndex).substring(strStart.length());
        return result;
    }

    public static void main(String[] args) {
        String application = "2020-12-25 10:01:58,074 INFO org.apache.hadoop.yarn.server.resourcemanager.RMAppManager$ApplicationSummary: appId=application_1598836826534_0110,name=select count(*) from aa(Stage-1),user=root,queue=root.default,state=FINISHED,trackingUrl=http://tsp-namenode-01:49016/proxy/application_1598836826534_0110/,appMasterHost=tsp-datanode-01,startTime=1608861681570,finishTime=1608861711459,finalStatus=SUCCEEDED,memorySeconds=179586,vcoreSeconds=64,preemptedAMContainers=0,preemptedNonAMContainers=0,preemptedResources=<memory:0\\, vCores:0>";
        String[] split = application.split(": ");

        String appId = subString(split[1], "appId=", ",");
        System.out.println(appId);

    }
}
